<?php
/**
 * 货品类型控制器 
 */
class TypeController extends IsLoginController{
	private $Model;
	public function __init(){
		parent::__init();
		$this->Model = K('type');
	}
	public function index(){
		$type = $this->Model->all();
		$this->assign('type',$type);
		$this->display();
	}
	//批量添加类型
	public function add(){
		if(IS_POST){
			if(!$this->Model->addType()){
				$this->error($this->Model->error);
			}
			$this->success('添加成功');
		}
		$this->display();
	}
	//修改类型
	public function edit(){
		//修改内容
		if(IS_POST){
			if(!$this->Model->edit()){
				$this->error($this->Model->error);
			}
			$this->success('修改成功');
		}
		if(!isset($_GET['tid']) && $_GET['tid'] == ''){
			$this->error('tid不能为空');
			return false;
		}else{
			$tid = Q('get.tid');
		}
		//页面赋值
		$tidData = $this->Model->where("tid = '{$tid}'")->find();
		$this->assign('tidData',$tidData);
		$this->display();
	}
	//类型删除
	public function del(){
		if(IS_GET){
			if(!$this->Model->delType()){
				$this->error($this->Model->error);
			}
			$this->success('删除成功');
		}
	}
	//添加属性
	public function addAttr(){
		$Model = K("type_attr");
		if(IS_POST){
			if(!$Model->addAttr()){
				$this->error($Model->error);
			}
			$this->success('添加成功');
		}
		$this->display();
	}
	//修改属性
	public function editAttr(){
		$Model = K("type_attr");
		//修改提交信息写入
		if(IS_POST){
			if(!$Model->editAttr()){
				$this->error($Model->error);
			}
			$this->success('修改成功');
		}
		//查询信息赋值页面信息
		if(!isset($_GET['aid']) && $_GET['aid'] == ''){
			$this->error('aid获取失败');
			return false;
		}else{
			$aid = Q('get.aid');
		}
		$Model = K("type_attr");
		$typeAttr = $Model->where("aid='{$aid}'")->find();
		$this->assign('typeAttr',$typeAttr);
		$this->display();
	}
	//属性列表
	public function attrList(){
		if(!isset($_GET['tid']) && $_GET['tid'] == ''){
			$this->error('tid不能为空');
			return false;
		}else{
			$tid = Q('get.tid');
		}
		$Model = K("type_attr");
		$typeAttr = $Model->where("type_tid='{$tid}'")->all();
		$this->assign('typeAttr',$typeAttr);
		$this->display();
	}
	//属性列表删除
	public function delAttr(){
		$Model = K("type_attr");
		if(IS_GET){
			if(!$Model->delAttr()){
				$this->error($Model->error);
			}
			$this->success('删除成功');
		}
	}
}
